/*
 * @lc app=leetcode.cn id=1013 lang=typescript
 *
 * [1013] 将数组分成和相等的三个部分
 */

// @lc code=start
//
function canThreePartsEqualSum(arr: number[]): boolean {
    // FIXME 使用 1/3 点法

    const sum = arr.reduce((a, b) => a + b, 0);
    if (sum % 3) return false;
    let avg = sum / 3;
    let count = 0;
    let temp = 0;
    arr.forEach((i, index) => {
        temp += i;
        if (temp === avg) {
            temp = 0;
            count++;
        }
    });
    return count >= 3;
}
// @lc code=end
